﻿using System;
using System.Collections.Generic;
using System.Text;
using Spring.Data.Generic;
using System.Data;
using SGIPSPManager.Domain;
using Framework.Message.SMS.SGIP;

namespace SGIPSPManager.DAOImpl
{
    public class MTMessageRowMapper : IRowMapper<MTMessage>
    {
        #region IRowMapper<MTMessage> Members

        public MTMessage MapRow(IDataReader reader, int rowNum)
        {
            MTMessage mtMessage = new MTMessage();
            if (reader["ID"] != null)
                mtMessage.ID = new Guid(reader["ID"].ToString());
            if (reader["SeqID"] != null)
                mtMessage.SeqID = long.Parse(reader["SeqID"].ToString());
            if (reader["AgentFlag"] != null)
                mtMessage.AgentFlag = (SubmitAgentFlag)byte.Parse(reader["AgentFlag"].ToString());
            if (reader["ChargeNumber"] != null)
                mtMessage.ChargeNumber = reader["ChargeNumber"].ToString();
            if (reader["SPID"] != null)
                mtMessage.SPID = reader["SPID"].ToString();
            if (reader["ExpireTime"] != null)
                mtMessage.ExpireTime = DateTime.Parse(reader["ExpireTime"].ToString());
            if (reader["FeeType"] != null)
                mtMessage.FeeType = (FeeType)byte.Parse(reader["FeeType"].ToString());
            if (reader["FeeValue"] != null)
                mtMessage.FeeValue = reader["FeeValue"].ToString();
            if (reader["GivenValue"] != null)
                mtMessage.GivenValue = reader["GivenValue"].ToString();
            if (reader["MessageCoding"] != null)
                mtMessage.MessageCoding = (MessageCoding)byte.Parse(reader["MessageCoding"].ToString());
            if (reader["MessageContent"] != null)
                mtMessage.MessageContent = reader["MessageContent"].ToString();
            if (reader["MessageLength"] != null)
                mtMessage.MessageLength = uint.Parse(reader["MessageLength"].ToString());
            if (reader["MessageType"] != null)
                mtMessage.MessageType = (SubmitMessageType)byte.Parse(reader["MessageType"].ToString());
            if (reader["MorelatetoMTFlag"] != null)
                mtMessage.MorelatetoMTFlag = (SubmitMorelatetoMTFlag)byte.Parse(reader["MorelatetoMTFlag"].ToString());
            if (reader["Priority"] != null)
                mtMessage.Priority = short.Parse(reader["Priority"].ToString());
            if (reader["ReportFlag"] != null)
                mtMessage.ReportFlag = (SubmitReportFlag)byte.Parse(reader["ReportFlag"].ToString());
            if (reader["ScheduleTime"] != null)
                mtMessage.ScheduleTime = DateTime.Parse(reader["ScheduleTime"].ToString());
            if (reader["ServiceType"] != null)
                mtMessage.ServiceType = reader["ServiceType"].ToString();
            if (reader["ScrID"] != null)
                mtMessage.ScrID = reader["ScrID"].ToString();
            if (reader["SubmitDate"] != null)
                mtMessage.SubmitDate = DateTime.Parse(reader["SubmitDate"].ToString());
            if (reader["TP_pid"] != null)
                mtMessage.TP_pid = int.Parse(reader["TP_pid"].ToString());
            if (reader["TP_udhi"] != null)
                mtMessage.TP_udhi = int.Parse(reader["TP_udhi"].ToString());
            if (reader["UserNumber"] != null)
                mtMessage.UserNumber = reader["UserNumber"].ToString();
            if (reader["ReSendTimes"] != null)
                mtMessage.ReSendTimes = int.Parse(reader["ReSendTimes"].ToString());
            if (reader["Status"] != null)
                mtMessage.Status = (MTStatus)byte.Parse(reader["Status"].ToString());
            //if (reader["FinishDate"] != null)
            //    mtMessage.FinishDate = DateTime.Parse(reader["FinishDate"].ToString());
            else
                mtMessage.FinishDate = null;
            return mtMessage;
        }

        #endregion
    }
}
